package com.trex.modules.utils;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

	/**
	 * 配置一个direct类型的交换机
	 * @return
	 */
	@Bean
	public DirectExchange directExchange() {
		return new DirectExchange("trexExchange");
	}
	
	/**
	 * 配置一个队列
	 * @return
	 */
	@Bean
	public Queue trexQueue() {
		return new Queue("trexQueue");
	}
	
	/**
	 * 配置一个交换机和队列的绑定
	 * @param trexQueue 需要绑定的对象
	 * @param directExchange 交换机
	 * @return
	 */
	@Bean
	public Binding trexBinding(Queue trexQueue,DirectExchange directExchange) {
		return BindingBuilder.bind(trexQueue).to(directExchange).with("trexRountingKey");
	}
}
